package cn.tedu.bece.front.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.tedu.bece.front.common.response.JsonResult;
import cn.tedu.bece.front.pojo.dto.GrowthRecordQuery;
import cn.tedu.bece.front.pojo.dto.GrowthRecordSaveParam;
import cn.tedu.bece.front.pojo.vo.GrowthRecordVO;
import cn.tedu.bece.front.service.GrowthRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/growthrecord")
public class GrowthRecordController {
    @Autowired
    GrowthRecordService growthRecordService;

    @PostMapping("/add")
    public JsonResult addrecord(@RequestBody GrowthRecordSaveParam growthRecordSaveParam){
        log.debug("添加宝宝身高体重记录:growthRecordSaveParam={}",growthRecordSaveParam);
        growthRecordService.add(growthRecordSaveParam);
        return JsonResult.success();
    }
    @GetMapping("/selectRecordList")
    public JsonResult selectRecordList(GrowthRecordQuery growthRecordQuery){
        log.debug("查询宝宝成长记录：growthRecordQuery={}",growthRecordQuery);
        Integer userId = StpUtil.getLoginIdAsInt();
        growthRecordQuery.setUserId(userId);
        List<GrowthRecordVO> list = growthRecordService.selectRecord(growthRecordQuery);
        return JsonResult.success(list);
    }
}